package com.xijia.wuyouwallet.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.xijia.wuyouwallet.MyApp;
import com.xijia.wuyouwallet.R;
import com.xijia.wuyouwallet.base.BaseActivity;
import com.xijia.wuyouwallet.utils.CharCheckUtil;

/**
 * Created by Administrator on 2017/8/24 0024.
 */

public class AddBankcardActivity extends BaseActivity implements View.OnClickListener{

    private ImageView addBankcard_back;
    private TextView addBankcard_name,addBankcard_config,addBankcard_title_tv;
    private EditText addBankcard_cardNum_et;

    private String bankNum;
    private String cardType;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_bankcard);
        initView();
    }


    private void initView(){
        addBankcard_back = (ImageView) findViewById(R.id.addBankcard_back);
        addBankcard_back.setOnClickListener(this);
        addBankcard_name = (TextView) findViewById(R.id.addBankcard_name);
        addBankcard_config = (TextView) findViewById(R.id.addBankcard_config);
        addBankcard_config.setOnClickListener(this);
        addBankcard_cardNum_et = (EditText) findViewById(R.id.addBankcard_cardNum_et);
        addBankcard_title_tv = (TextView) findViewById(R.id.addBankcard_title_tv);
        initData();
    }

    private void initData(){
        addBankcard_name.setText(MyApp.userData.getData().getNick_name());
        cardType = getIntent().getStringExtra("cardType");
        if (cardType.equals("0")){
            addBankcard_title_tv.setText("添加信用卡");
        }else if (cardType.equals("1")){
            addBankcard_title_tv.setText("添加银行卡");
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.addBankcard_back:
                finish();
                break;
            case R.id.addBankcard_config:
                bankNum = addBankcard_cardNum_et.getText().toString();
                if (bankNum.isEmpty()){
                    showToast("请输入银行卡号");
                    return;
                }
                if (!CharCheckUtil.checkBankCard(bankNum)){
                    showToast("银行卡号输入有误");
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putString("cardNum",bankNum);
                bundle.putString("cardType",cardType);
                jumpToPage(FillBankcardActivity.class,bundle,true);
                break;
        }
    }
}
